package leetcode.剑指offer.后40;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/7/31 21:53
 * @description：https://leetcode-cn.com/problems/ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof/
 */
public class 剑指_46_把数字翻译成字符串 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.translateNum(26));
    }

    class Solution {
        int count = 0;
        public int translateNum(int num) {
            dfs(num + "", 0);
            return count;
        }

        private void dfs(String num, int i) {
            if (i == num.length()) {
                count++;
                return;
            }
            dfs(num, i + 1);
            if (num.charAt(i) != '0' && (i + 1) < num.length()) {
                int cur = Integer.parseInt(num.substring(i, i + 2));
                if (cur >= 10 && cur <= 25) {
                    dfs(num, i + 2);
                }
            }
        }
    }
}
